package com.f8q8.agent.service.impl;

import com.f8q8.agent.entity.TaskEntity;
import com.f8q8.agent.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 任务服务实现
 *
 * @author zxl78
 * @version 1.0
 * @since 2023/12/05 0005 17:01:02
 */
@Slf4j
@Service
public class TaskServiceImpl implements TaskService {

    private final static List<TaskEntity> taskList = new CopyOnWriteArrayList<>();

    private final static Map<String, String> deviceMap = new ConcurrentHashMap<>();
    private static boolean taskRunFlag = false;

    @Override
    public void startTask() {
        taskRunFlag = true;
    }

    @Override
    public void stopTask() {
        taskRunFlag = false;
    }

    @Override
    public void resetTask() {
        taskList.clear();
    }

    @Override
    public void insertTask(TaskEntity taskEntity) {
        // 插入第0个位置，优先处理
        taskList.add(0, taskEntity);
    }

    @Override
    public boolean getTaskFlag() {
        return taskRunFlag;
    }

    @Override
    public List<TaskEntity> findTaskList() {
        return taskList;
    }

    @Override
    public Map<String, String> findDeviceMap() {
        return deviceMap;
    }
}
